import React, { Component } from 'react'
import { connect } from 'react-redux'
import {InitState} from '../../types/index'
import {RouteComponentProps} from 'react-router-dom'
import '../../css/index.scss'
interface Props extends InitState,RouteComponentProps{
    changeDeit():void
    changeAll():void
}
interface State {
    
}

export class Car extends Component<Props, State> {
    state = {
        deit:false,
        
    }
    changeDeit=()=>{

    }
    render() {
        return (
            <div className='car'>
                <div className='carmain'>
                    {
                        this.props.carList.map((item,index)=>{
                            return <li key={index}>
                                <dl>
                                    <dt>
                                        <input type='checkbox' />
                                    </dt>
                                    <dt>
                                        <img src={item.img} alt="" />
                                    </dt>
                                    <dd>
                                        <p>{item.title}</p>
                                        <p>￥{item.price}</p>
                                        <span>X{item.num}</span>
                                    </dd>
                                </dl>
                            </li>
                        })
                    }
                </div>
                <div className='carfooter'>
                    <p><input type='checkbox' onChange={()=>this.props.changeAll()}/> 已选({this.props.number}) ￥{this.props.sum}</p>
                    <p onClick={()=>this.changeDeit}>编辑</p>
                    <p>下单</p>
                </div>
            </div>
        )
    }
}

const mapStateToProps = (state:Props) => ({

    carList:state.carList,
    sum:state.sum,
    number:state.number,
})

const mapDispatchToProps = (dispatch:Function)=>({
    changeAll:()=>dispatch({type:'SET_CAR_ALL'})
})

export default connect(mapStateToProps, mapDispatchToProps)(Car)
